﻿using System.Diagnostics;
using System.Text;
using LuckyShell.ShellOrders;
using LuckyShell.ShellValues;

namespace LuckyShell.Commands;

public class ShowCommand(List<ShellValue> values) : Command(values)
{
    public override object Run(ref VariateManager manager)
    {
        switch (Values.Count)
        {
            case 0:
                Console.WriteLine();
                break;
            case 1:
                var v = Values[0].GetValue(ref manager);
                if (v is string s)
                {
                    if (File.Exists(s))
                    {
                        manager.Order(s);
                        break;
                    }

                    if (Directory.Exists(s))
                    {
                        var d = new DirectoryInfo(s);
                        foreach (var info in d.GetFileSystemInfos())
                            Console.WriteLine(info.Name);
                        break;
                    }
                    Console.WriteLine(v);
                }
                else
                {
                    Console.WriteLine(v);
                }
                break;
            default:
                var builder = new StringBuilder();
                foreach (var value in Values)
                    builder.Append(value.GetValue(ref manager));
                Console.WriteLine(builder.ToString());
                break;
        }

        return new VoidValue();
    }
}